/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.agreement.service.supplychainserviceagreement;

import com.jeesite.common.entity.Page;
import com.jeesite.common.service.CrudService;
import com.jeesite.modules.agreement.dao.supplychainserviceagreement.SupplyChainServiceAgreementDao;
import com.jeesite.modules.agreement.entity.supplychainserviceagreement.SupplyChainServiceAgreement;
import com.jeesite.modules.custom.service.CodeRuleService;
import com.jeesite.modules.file.utils.FileUploadUtils;
import com.jeesite.modules.sys.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 供应链服务协议Service
 * @author Kilo
 * @version 2021-03-03
 */
@Service
@Transactional(readOnly=true)
public class SupplyChainServiceAgreementService extends CrudService<SupplyChainServiceAgreementDao, SupplyChainServiceAgreement> {

	@Autowired
	private CodeRuleService codeRuleService;

	/**
	 * 获取单条数据
	 * @param supplyChainServiceAgreement
	 * @return
	 */
	@Override
	public SupplyChainServiceAgreement get(SupplyChainServiceAgreement supplyChainServiceAgreement) {
		return super.get(supplyChainServiceAgreement);
	}
	
	/**
	 * 查询分页数据
	 * @param supplyChainServiceAgreement 查询条件
	 * @return
	 */
	@Override
	public Page<SupplyChainServiceAgreement> findPage(SupplyChainServiceAgreement supplyChainServiceAgreement) {
		return super.findPage(supplyChainServiceAgreement);
	}
	
	/**
	 * 保存数据（插入或更新）
	 * @param supplyChainServiceAgreement
	 */
	@Override
	@Transactional(readOnly=false)
	public void save(SupplyChainServiceAgreement supplyChainServiceAgreement) {
		if(supplyChainServiceAgreement.getIsNewRecord()){
			supplyChainServiceAgreement.setSupplyChainServiceAgreementCode(codeRuleService.getCode("SupplyChainServiceAgreement"));
			supplyChainServiceAgreement.setCreateBy(UserUtils.getUser().getUserCode());
			supplyChainServiceAgreement.setUpdateBy(UserUtils.getUser().getUserCode());
		}else{
			supplyChainServiceAgreement.setUpdateBy(UserUtils.getUser().getUserCode());
		}
		super.save(supplyChainServiceAgreement);
		if (supplyChainServiceAgreement.getIsNewRecord()){
			codeRuleService.updateCurrentNumber("SupplyChainServiceAgreement");
		}
		// 保存上传附件
		FileUploadUtils.saveFileUpload(supplyChainServiceAgreement.getId(), "supplyChainServiceAgreement_file");
	}
	
	/**
	 * 更新状态
	 * @param supplyChainServiceAgreement
	 */
	@Override
	@Transactional(readOnly=false)
	public void updateStatus(SupplyChainServiceAgreement supplyChainServiceAgreement) {
		super.updateStatus(supplyChainServiceAgreement);
	}
	
	/**
	 * 删除数据
	 * @param supplyChainServiceAgreement
	 */
	@Override
	@Transactional(readOnly=false)
	public void delete(SupplyChainServiceAgreement supplyChainServiceAgreement) {
		super.delete(supplyChainServiceAgreement);
	}
	
}